package com.isdepci.project.eleLoad.controller;

import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;

import com.isdepci.project.carbon.domain.param.WeatherDataExcel;
import com.isdepci.project.eleLoad.domain.AEngineeringList;
import com.isdepci.project.eleLoad.service.IAEngineeringListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工程清单Controller
 *
 * @author isdepci
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/eleLoad/engineering")
public class AEngineeringListController extends BaseController
{
    @Autowired
    private IAEngineeringListService aEngineeringListService;




    /**
     * 计算
     * @param engineeringList
     * @return
     */
    @PostMapping("/calculateFuel")
    public AjaxResult calculateFuel(@RequestBody List<AEngineeringList> engineeringList) {
        return aEngineeringListService.calculateFuel(engineeringList);
    }


    /**
     * 查询工程清单列表
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:engineering:list')")
    @GetMapping("/list")
    public TableDataInfo list(AEngineeringList aEngineeringList)
    {
        startPage();
        List<AEngineeringList> list = aEngineeringListService.selectAEngineeringListList(aEngineeringList);
        return getDataTable(list);
    }

    /**
     * 导出工程清单列表
     */
//    @PreAuthorize("@ss.hasPermi('eleLoad:engineering:export')")
    @Log(title = "工程清单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AEngineeringList aEngineeringList)
    {
        List<AEngineeringList> list = aEngineeringListService.selectAEngineeringListList(aEngineeringList);
        ExcelUtil<AEngineeringList> util = new ExcelUtil<AEngineeringList>(AEngineeringList.class);
        return util.exportExcel(list, "engineering");
    }



    /**
     * 上传保存数据
     * @param excel
     * @return
     */
    @PostMapping("/changeData")
    public AjaxResult changeDataByProjectId(@RequestBody WeatherDataExcel excel) {
        return aEngineeringListService.changeDataByProjectId(excel);
    }


    /**
     * 保存excel数据到数据库
     * @param excelData
     * @return
     */
    @PostMapping("/saveEngineeringData")
    public AjaxResult saveRegionalData(@RequestBody List<AEngineeringList> excelData) {
        for(AEngineeringList data: excelData) {
            aEngineeringListService.insertAEngineeringList(data);
        }
        return AjaxResult.success("successfully");
    }



    /**
     * 获取工程清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:engineering:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(aEngineeringListService.selectAEngineeringListById(id));
    }

    /**
     * 新增工程清单
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:engineering:add')")
    @Log(title = "工程清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AEngineeringList aEngineeringList)
    {
        return toAjax(aEngineeringListService.insertAEngineeringList(aEngineeringList));
    }

    /**
     * 修改工程清单
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:engineering:edit')")
    @Log(title = "工程清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AEngineeringList aEngineeringList)
    {
        return toAjax(aEngineeringListService.updateAEngineeringList(aEngineeringList));
    }

    /**
     * 删除工程清单
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:engineering:remove')")
    @Log(title = "工程清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aEngineeringListService.deleteAEngineeringListByIds(ids));
    }
}
